<template>
	<view class="main">
		<view class="summary">
			<image class="back" src="/static/error_back.jpg" mode="widthFix"></image>
			<view class="content">
				<view class="title">
					全部错题
				</view>
				<view class="num">
					{{count}}题
				</view>
			</view>

		</view>
		<view class="operation">
			<view class="btn" @click="redo">
				错题重做
			</view>
			<view class="btn" @click="look">
				错题查看
			</view>
		</view>
		<view class="empty" @click="emptyError">
			清空我的错题
		</view>
	</view>
</template>

<script>
	import {
		errorRecord,
		emptyErrSubject,
		emptyErrVipSubject
	} from "@/api/index.js"
	export default {
		data() {
			return {
				count: 0,
				userInfo: '',
				subject: '',
				isVip: false
			};
		},
		mounted() {

		},
		onLoad(option) {
			this.isVip = option.isVip
			if (this.isVip == '1') {
				this.subject = uni.getStorageSync("vipSubject")
			} else {
				this.subject = uni.getStorageSync("subjectType")
			}

			this.userInfo = uni.getStorageSync("userInfo")

			this.getError()
		},
		methods: {
			//重做错题
			redo() {
				if (this.count == 0) {
					uni.showToast({
						title: "没有错题可以重做",
						duration: 2000,
						icon: 'none'
					})
					return
				}
				uni.navigateTo({
					url: "/pages/subject/errorRedo?isVip=" + this.isVip
				})
			},
			//我的错题
			getError() {
				errorRecord({
					page_size: 10,
					page: 1,
					subject: this.subject
				}).then(res => {
					this.count = res.data.count
				})
			},
			// 清空错题
			emptyError() {
				let that = this
				wx.showModal({
					title: '提示',
					content: `是否清除所有错题？`,
					success(res) {
						if (res.confirm) {
							emptyErrSubject({
								subject: that.subject
							}).then(res => {
								if (res.code == 1) {
									that.getError()
								}
							})
						} else if (res.cancel) {
							console.log('用户点击取消')
						}
					}
				})
			},
			//错题查看
			look() {
				if (this.count == 0) {
					uni.showToast({
						title: "没有错题可以查看",
						duration: 2000,
						icon: 'none'
					})
					return
				}
				uni.navigateTo({
					url: "/pages/subject/errorLook?isVip=" + this.isVip
				})
			},

		}
	}
</script>

<style lang="scss">
	page {
		// background-color: #fff;
	}

	.summary {
		position: relative;
		height: 600rpx;

		.back {
			width: 100%;
			position: absolute;
			top: 0;
			left: 0;
		}

		.content {
			position: absolute;
			left: 0;
			top: 240rpx;
			text-align: center;
			color: #fff;
			z-index: 999;
			width: 100%;

			.title {
				font-size: 30rpx;
				margin-bottom: 20rpx;
			}

			.num {
				font-size: 32rpx;
			}
		}
	}

	.operation {
		display: flex;
		align-items: center;
		width: 80%;
		margin-left: 10%;
		justify-content: space-between;

		.btn {
			color: #fff;
			background-color: #4495E6;
			border-radius: 80rpx;
			height: 80rpx;
			line-height: 80rpx;
			font-size: 28rpx;
			width: 40%;
			text-align: center;
		}
	}

	.empty {
		width: 80%;
		margin-left: 10%;
		border-radius: 80rpx;
		height: 80rpx;
		line-height: 80rpx;
		font-size: 28rpx;
		background-color: #D22E25;
		color: #fff;
		margin-top: 100rpx;
		text-align: center;
	}

	@media (min-width:450px) {
		.summary {
			height: 760rpx;

			.content {
				top: 320rpx;
			}
		}

	}
</style>